/// 举报信息模型

/// 举报项目
class ReportItem {
  final int? reportId;
  final String? reportType;
  final String? reportReason;
  final int? contentId;
  final int? reporterId;
  final String? reporterName;
  final int? processStatus; // 0:待处理, 1:处理中, 2:已处理, 3:已驳回
  final String? processResult;
  final bool isProcessed;
  final String? reportTime;
  final String? createdAt;
  final Map<String, dynamic>? extraData;

  ReportItem({
    this.reportId,
    this.reportType,
    this.reportReason,
    this.contentId,
    this.reporterId,
    this.reporterName,
    this.processStatus,
    this.processResult,
    this.isProcessed = false,
    this.reportTime,
    this.createdAt,
    this.extraData,
  });

  factory ReportItem.fromJson(Map<String, dynamic> json) {
    return ReportItem(
      reportId: json['reportId'] as int? ?? json['report_id'] as int?,
      reportType: json['reportType'] as String? ?? json['report_type'] as String?,
      reportReason: json['reportReason'] as String? ?? json['report_reason'] as String?,
      contentId: json['contentId'] as int? ?? json['content_id'] as int?,
      reporterId: json['reporterId'] as int? ?? json['reporter_id'] as int?,
      reporterName: json['reporterName'] as String? ?? json['reporter_name'] as String?,
      processStatus: json['processStatus'] as int? ?? json['process_status'] as int? ?? 0,
      processResult: json['processResult'] as String? ?? json['process_result'] as String?,
      isProcessed: json['isProcessed'] as bool? ?? json['is_processed'] as bool? ?? false,
      reportTime: json['reportTime'] as String? ?? json['report_time'] as String?,
      createdAt: json['createdAt'] as String? ?? json['created_at'] as String?,
      extraData: json['extraData'] as Map<String, dynamic>? ?? json['extra_data'] as Map<String, dynamic>?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'reportId': reportId,
      'reportType': reportType,
      'reportReason': reportReason,
      'contentId': contentId,
      'reporterId': reporterId,
      'reporterName': reporterName,
      'processStatus': processStatus,
      'processResult': processResult,
      'isProcessed': isProcessed,
      'reportTime': reportTime,
      'createdAt': createdAt,
      'extraData': extraData,
    };
  }
}

/// 举报信息分页数据
class ReportPagination {
  final int? page;
  final int? pageSize;
  final int? total;
  final int? totalPages;
  final bool hasNextPage;

  ReportPagination({
    this.page,
    this.pageSize,
    this.total,
    this.totalPages,
    this.hasNextPage = false,
  });

  factory ReportPagination.fromJson(Map<String, dynamic> json) {
    final currentPage = json['page'] as int? ?? json['current_page'] as int? ?? 1;
    final total = json['total'] as int? ?? 0;
    final totalPages = json['totalPages'] as int? ?? json['total_pages'] as int? ?? 1;
    
    return ReportPagination(
      page: currentPage,
      pageSize: json['pageSize'] as int? ?? json['page_size'] as int? ?? 20,
      total: total,
      totalPages: totalPages,
      hasNextPage: currentPage < totalPages,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'page': page,
      'pageSize': pageSize,
      'total': total,
      'totalPages': totalPages,
      'hasNextPage': hasNextPage,
    };
  }
}

/// 举报信息响应
class ReportInfoResponse {
  final String status;
  final String? message;
  final List<ReportItem> reports;
  final ReportPagination? pagination;

  ReportInfoResponse({
    required this.status,
    this.message,
    required this.reports,
    this.pagination,
  });

  bool get isSuccess => status == 'success';

  factory ReportInfoResponse.fromJson(Map<String, dynamic> json) {
    final reportsList = json['reports'] as List<dynamic>? ?? json['data'] as List<dynamic>? ?? [];
    
    return ReportInfoResponse(
      status: json['status'] as String? ?? 'error',
      message: json['message'] as String?,
      reports: reportsList
          .map((item) => ReportItem.fromJson(item as Map<String, dynamic>))
          .toList(),
      pagination: json['pagination'] != null
          ? ReportPagination.fromJson(json['pagination'] as Map<String, dynamic>)
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      'reports': reports.map((r) => r.toJson()).toList(),
      'pagination': pagination?.toJson(),
    };
  }
}

